#ifndef SOURCE_H
#define SOURCE_H

#include <windows.h>
#include <wininet.h>
#include <stdio.h>

#pragma comment(lib, "wininet.lib")

#define NETFILE_BUFFER_SIZE (8 * 1024) // 512KB 缓冲区

typedef struct {
    HINTERNET hInternet;
    HINTERNET hFile;
    DWORD fileSize;
    DWORD bytesRead;
    char buffer[NETFILE_BUFFER_SIZE];
    DWORD bufferSize;
    DWORD bufferPos;
    DWORD filePos;
    int isGzip;             // 是否是 GZIP 压缩内容
} NetFile;

NetFile* net_fopen(const char* url, const char* mode);
void net_fclose(NetFile* netFile);
size_t net_fread(void* buffer, size_t size, size_t count, NetFile* netFile);
int net_fseek(NetFile* netFile, long offset, int origin);

#endif // SOURCE_H
